package com.zmq.pic.test;

import java.util.List;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zmq.pic.entity.PicUser;
import com.zmq.pic.service.impl.PicUserServiceImpl;

public class PicUserServiceTestCase {

	private static PicUserServiceImpl picUserService;

	@BeforeClass
	public static void init() {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"applicationContext.xml");
		picUserService = (PicUserServiceImpl) context
				.getBean("picUserServiceImpl");
	}

	@Test
	public void testSave() {

		java.util.Date date = new java.util.Date();

		PicUser picUser = new PicUser();

		picUser.setUserName("zmq");

		picUser.setPassword("123456");

		picUser.setCreateTime(date);

		picUser.setUpdateTime(date);

		picUserService.save(picUser);

		Assert.assertNotNull(picUser.getId());
	}

	@Test
	public void testFindById() {

		PicUser picUser = new PicUser();

		picUser.setId(1l);

		PicUser _picUser = picUserService.findById(picUser);

		Assert.assertEquals(_picUser.getId(), picUser.getId());
	}

	@Test
	public void testFindAll() {

		List<PicUser> list = picUserService.findAll();

		Assert.assertNotNull(list);

		for (PicUser picUser : list) {

			System.out.println("[" + picUser.getUserName() + ","
					+ picUser.getPassword() + "]");
		}
	}

	@Test
	public void testUpdate() {

		PicUser picUser = new PicUser();

		picUser.setId(1l);

		picUser = picUserService.findById(picUser);

		String newPwd = picUser.getPassword() + "111";

		picUser.setPassword(newPwd);

		picUserService.update(picUser);

		Assert.assertEquals(picUser.getPassword(), newPwd);

	}
}
